import { Controller } from "../../../../mvc/core/Controller";
import { PetIslandPosChangePanel } from "../PetIslandPosChangePanel";
import { PetIslandPowerBasePanel } from "../PetIslandPowerBasePanel";
import { PetIslandPowerIntrPanel } from "../PetIslandPowerIntrPanel";
import { PetIslandFightListPanel } from "../PetIslandFightListPanel";
import { PetIslandPicRulePanel } from "../PetIslandPicRulePanel";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { IView } from "../../../../mvc/interfaces/IView";
import { WindowEvent } from "../../../../component/window/WindowEvent";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { GameProxy } from "../../../mvc/GameProxy";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SRobIslandPlayer } from "../../../../../Message/Game/SRobIslandPlayer";
import { SRobIslandGuildInfo } from "../../../../../Message/Game/SRobIslandGuildInfo";
import { SRobIslandGuildMemberInfo } from "../../../../../Message/Game/SRobIslandGuildMemberInfo";
import { DataEvent } from "../../../events/DataEvent";
import { SRobIslandGuildFightingInfo } from "../../../../../Message/Game/SRobIslandGuildFightingInfo";
import { SGuildRobIslandLog } from "../../../../../Message/Game/SGuildRobIslandLog";
import { SMoney } from "../../../../../Message/Game/SMoney";
import { SRobIslandFightPetList } from "../../../../../Message/Game/SRobIslandFightPetList";
import { PetIslandMemberOperVo } from "../vo/PetIslandMemberOperVo";
import { GameController } from "../../../mvc/GameController";
import { PetIslandupdatePetVo } from "../vo/PetIslandupdatePetVo";
type int = number;
//class PetIslandPowerBaseController
    
    export  class PetIslandPowerBaseController extends Controller
    {
        constructor()
        {
            super();
            return;
        }

        public get posChangePanel(): PetIslandPosChangePanel
        {
            if (!this._posChangePanel) 
            {
                this._posChangePanel = new PetIslandPosChangePanel(PetIslandPowerBasePanel(view));
            }
            return this._posChangePanel;
        }

        /* internal  */get powerIntrPanel(): PetIslandPowerIntrPanel
        {
            if (!this._powerIntrPanel) 
            {
                this._powerIntrPanel = new PetIslandPowerIntrPanel();
            }
            return this._powerIntrPanel;
        }

        /* internal  */get fightListPanel(): PetIslandFightListPanel
        {
            if (!this._fightListPanel) 
            {
                this._fightListPanel = new PetIslandFightListPanel();
            }
            return this._fightListPanel;
        }

        /* internal  */get picRulePanel(): PetIslandPicRulePanel
        {
            if (!this._picRulePanel) 
            {
                this._picRulePanel = new PetIslandPicRulePanel();
            }
            return this._picRulePanel;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.PetIslandPowerBaseDataReq, this.onPetIslandPowerBaseDataReqHandler);
            Dispatcher.addEventListener(EventName.PetIslandPosChangePanelShow, this.onPetIslandPosChangePanelShowHandler);
            Dispatcher.addEventListener(EventName.PetIslandMemberOper, this.onPetIslandMemberOperHandler);
            Dispatcher.addEventListener(EventName.PetIslandPowerBaseViewShowByIndex, this.onPetIslandPowerBaseViewShowByIndexHandler);
            Dispatcher.addEventListener(EventName.PetIslandPowerIntrShow, this.onPetIslandPowerIntrShowHandler);
            Dispatcher.addEventListener(EventName.PetIslandupdatePet, this.onPetIslandupdatePetHandler);
            Dispatcher.addEventListener(EventName.PetIslandFightListReq, this.onPetIslandFightListReqHandler);
            Dispatcher.addEventListener(EventName.PetIslandAddAttackTime, this.onPetIslandAddAttackTimeHandler);
            Dispatcher.addEventListener(EventName.PetIslandPicRulePanelShow, this.onPetIslandPicRulePanelShowHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandFightPetList, this.onPetIslandFightPetList);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandGuildInfo, this.petIslandGuildInfo);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandPlayerInfo, this.petIslandPlayerInfo);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this.petIslandPowerBasePanel) 
            {
                this.petIslandPowerBasePanel = new PetIslandPowerBasePanel();
                this.petIslandPowerBasePanel.addEventListener(WindowEvent.SHOW, this.showPanel);
                this.petIslandPowerBasePanel.addEventListener(WindowEvent.CLOSE, this.closePanel);
            }
            return this.petIslandPowerBasePanel;
        }

        /* internal  */showPanel(arg1: WindowEvent): void
        {
            Dispatcher.addEventListener(EventName.PetBagUpdate, this.onPetBagUpdateHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandGuildMemberInfo, this.petIslandGuildMemberInfo);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandGuildFightingInfo, this.petIslandGuildFightingInfo);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRobIslandGuildLog, this.petIslandGuildLog);
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.onMoneyUpdateHandler);
            if (!this._time) 
            {
                this._time = new Object /* flash.utils.Timer */(30000);
            }
            this._time.addEventListener(flash.events.TimerEvent.TIMER, this.onTimerHandler);
            this._time.start();
            return;
        }

        /* internal  */closePanel(arg1: WindowEvent): void
        {
            Dispatcher.removeEventListener(EventName.PetBagUpdate, this.onPetBagUpdateHandler);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicRobIslandGuildMemberInfo, this.petIslandGuildMemberInfo);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicRobIslandGuildFightingInfo, this.petIslandGuildFightingInfo);
            NetDispatcher.removeCmdListener(EPublicCommand._ECmdPublicRobIslandGuildLog, this.petIslandGuildLog);
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.onMoneyUpdateHandler);
            this._time.stop();
            this._time.removeEventListener(flash.events.TimerEvent.TIMER, this.onTimerHandler);
            return;
        }

        /* internal  */onTimerHandler(arg1: Object /* flash.events.TimerEvent */): void
        {
            GameProxy.petIsland.getGuildInfo();
            GameProxy.petIsland.getPlayerInfo();
            return;
        }

        /* internal  */petIslandPlayerInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRobIslandPlayer;
            cache.petIsland.playerInfo = loc1;
            if (_view && !view.isHide) 
            {
                PetIslandPowerBasePanel(view).petIslandGuildPersonalInfoUpata(loc1);
                PetIslandPowerBasePanel(view).petIslandGuildInfoUpdata(cache.petIsland.powerBaseInfo);
            }
            return;
        }

        /* internal  */petIslandGuildInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRobIslandGuildInfo;
            cache.petIsland.powerBaseInfo = loc1;
            if (_view && !view.isHide) 
            {
                PetIslandPowerBasePanel(view).petIslandGuildInfoUpdata(loc1);
            }
            return;
        }

        /* internal  */petIslandGuildMemberInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRobIslandGuildMemberInfo;
            PetIslandPowerBasePanel(view).petIslandGuildMemberInfoUpata(loc1);
            return;
        }

        /* internal  */onPetBagUpdateHandler(arg1: DataEvent): void
        {
            if (this.petIslandPowerBasePanel && !this.petIslandPowerBasePanel.isHide) 
            {
                this.petIslandPowerBasePanel.setPetListComBo();
            }
            return;
        }

        /* internal  */petIslandGuildFightingInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRobIslandGuildFightingInfo;
            PetIslandPowerBasePanel(view).petIslandGuildFightingInfoUpata(loc1);
            PetIslandPowerBasePanel(view).broadcastUpdata(loc1.fightings);
            return;
        }

        /* internal  */petIslandGuildLog(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SGuildRobIslandLog;
            PetIslandPowerBasePanel(view).petIslandGuildLogUpdata(loc1);
            return;
        }

        /* internal  */onMoneyUpdateHandler(arg1: SMoney=null): void
        {
            PetIslandPowerBasePanel(view).onMoneyUpdate();
            return;
        }

        /* internal  */onPetIslandFightPetList(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SRobIslandFightPetList;
            this.fightListPanel.data = loc1;
            this.fightListPanel.show();
            return;
        }

        /* internal  */onPetIslandPowerBaseDataReqHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            var loc2=loc1;
            switch (loc2) 
            {
                case 0:
                {
                    GameProxy.petIsland.getPlayerInfo();
                    GameProxy.petIsland.getGuildInfo();
                    GameProxy.petIsland.getGuildFightingInfo();
                    break;
                }
                case 1:
                {
                    GameProxy.petIsland.getGuildMemberInfo();
                    break;
                }
                case 2:
                {
                    GameProxy.petIsland.getGuildLog();
                    break;
                }
            }
            return;
        }

        /* internal  */onPetIslandPosChangePanelShowHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data.vo as SRobIslandPlayer;
            var loc2=arg1.data.dic as Map<any, any> /* flash.utils.Dictionary */;
            if (this.posChangePanel.isHide) 
            {
                this.posChangePanel.show();
            }
            this.posChangePanel.setData(loc1, loc2);
            return;
        }

        /* internal  */onPetIslandMemberOperHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as PetIslandMemberOperVo;
            GameProxy.petIsland.memberOper(loc1);
            return;
        }

        /* internal  */onPetIslandPowerBaseViewShowByIndexHandler(arg1: DataEvent): void
        {
            GameController.petIsland.mapController.view.hide();
            var loc1=arg1.data as int;
            view.show();
            PetIslandPowerBasePanel(view).showPanelByIndex(loc1);
            return;
        }

        /* internal  */onPetIslandPowerIntrShowHandler(arg1: DataEvent): void
        {
            this.powerIntrPanel.show();
            return;
        }

        /* internal  */onPetIslandupdatePetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as PetIslandupdatePetVo;
            GameProxy.petIsland.updatePet(loc1);
            return;
        }

        /* internal  */onPetIslandFightListReqHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.petIsland.getFightPetList(loc1);
            return;
        }

        /* internal  */onPetIslandAddAttackTimeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.petIsland.addAttackTimes(loc1);
            return;
        }

        /* internal  */onPetIslandPicRulePanelShowHandler(arg1: DataEvent): void
        {
            this.picRulePanel.show();
            return;
        }

        public /* var */petIslandPowerBasePanel: PetIslandPowerBasePanel;

        /* internal */ /* var */_posChangePanel: PetIslandPosChangePanel;

        /* internal */ /* var */_powerIntrPanel: PetIslandPowerIntrPanel;

        /* internal */ /* var */_fightListPanel: PetIslandFightListPanel;

        /* internal */ /* var */_picRulePanel: PetIslandPicRulePanel;

        /* internal */ /* var */_time: Object /* flash.utils.Timer */;
    }
